home *** CD-ROM | disk | FTP | other *** search
/ HAM Radio 1997 / HAM Radio 1997.iso / vcls / wfc007.000 / include / cnmpipe.hpp < prev    next >
C/C++ Source or Header  |  1996-04-08  |  4KB  |  137 lines

  1. #ifndef NAMED_PIPE_CLASS_HEADER
  2.  
  3. /*
  4. ** Author: Samuel R. Blackburn
  5. ** CI$: 76300,326
  6. ** Internet: sammy@sed.csc.com
  7. **
  8. ** You can use it any way you like.
  9. */
  10.  
  11. #define NAMED_PIPE_CLASS_HEADER
  12.  
  13. class CNamedPipe : public CDummyFile
  14. {
  15.    public:
  16.  
  17.       enum NamedPipeTypes
  18.       {
  19.          typeServerEnd = PIPE_SERVER_END,
  20.          typeMessage   = PIPE_TYPE_MESSAGE
  21.       };
  22.  
  23.    private:
  24.  
  25.       void m_Initialize( DWORD input_buffer_size, DWORD output_buffer_size );
  26.  
  27.    protected:
  28.  
  29.       HANDLE m_PipeHandle;
  30.  
  31.       BOOL m_AutomaticallyDelete;
  32.  
  33.       NamedPipeTypes m_TypeOfPipe; // From GetInfo()
  34.  
  35.       DWORD m_ErrorCode;
  36.  
  37.       LPVOID m_InputBuffer;
  38.       LPVOID m_OutputBuffer;
  39.  
  40.       DWORD m_MaximumNumberOfInstances; // From GetInfo()
  41.  
  42.       DWORD m_InputBufferSize;
  43.       DWORD m_OutputBufferSize;
  44.       DWORD m_NumberOfBytesToWrite;
  45.       DWORD m_NumberOfBytesRead;
  46.       DWORD m_Timeout;
  47.  
  48.       CString m_PipeName;
  49.  
  50.       /*
  51.       ** Information returned from GetNamedPipeHandleState()
  52.       */
  53.  
  54.       DWORD m_PipeState;
  55.       DWORD m_NumberOfInstances;
  56.       DWORD m_MaximumNumberOfBytesBeforeRemoteTransmission;
  57.       DWORD m_MaximumNumberOfMillisecondsBeforeRemoteTransmission;
  58.  
  59.       CString m_UserNameOfClientProcess;
  60.       
  61.    public:
  62.  
  63.       CNamedPipe( DWORD input_buffer_size = 4096, DWORD output_buffer_size = 4096 );
  64.  
  65.       /*
  66.       ** Destructor should be virtual according to MSJ article in Sept 1992
  67.       ** "Do More with Less Code:..."
  68.       */
  69.  
  70.       virtual ~CNamedPipe();
  71.  
  72.       /*
  73.       ** The Win32 API
  74.       */
  75.  
  76.       virtual BOOL Call( CString& name_of_pipe, 
  77.                          LPVOID   write_buffer, 
  78.                          DWORD    size_of_write_buffer, 
  79.                          LPVOID   read_buffer, 
  80.                          DWORD    size_of_read_buffer, 
  81.                          DWORD   *address_of_number_of_bytes_read,
  82.                          DWORD    number_of_milliseconds_to_wait = NMPWAIT_WAIT_FOREVER ); // CallNamedPipe
  83.  
  84.       virtual BOOL Connect( LPOVERLAPPED overlapped_p = NULL ); // ConnectNamedPipe
  85.  
  86.       virtual BOOL Create( LPCTSTR server_name,
  87.                            LPCTSTR name_of_pipe,
  88.                            DWORD   open_mode       = PIPE_ACCESS_DUPLEX,
  89.                            DWORD   type_of_pipe    = PIPE_TYPE_BYTE,
  90.                            DWORD   number_of_pipes = PIPE_UNLIMITED_INSTANCES,
  91.                            LPSECURITY_ATTRIBUTES security_attributes_p = NULL );
  92.  
  93.       virtual BOOL Disconnect( void ); // DisconnectNamedPipe
  94.       virtual BOOL GetState( void ); // GetNamedPipeHandleState
  95.       virtual BOOL GetInformation( void ); // GetNamedPipeInfo
  96.  
  97.       virtual BOOL Peek( LPVOID buffer_address,
  98.                          DWORD  size_of_buffer,
  99.                          DWORD& number_of_bytes_read,
  100.                          DWORD& number_of_bytes_available,
  101.                          DWORD& number_of_bytes_remaining_in_message );
  102.       
  103.       virtual BOOL SetState( DWORD new_pipe_mode,
  104.                              DWORD maximum_number_of_bytes_before_transmission, 
  105.                              DWORD maximum_number_of_milliseconds_before_transmission );
  106.       
  107.       virtual BOOL Transact( LPOVERLAPPED overlapped_p = NULL ); // TransactNamedPipe
  108.       
  109.       virtual BOOL Wait( LPCTSTR server_name,
  110.                          LPCTSTR name_of_pipe, 
  111.                          DWORD   number_of_milliseconds = NMPWAIT_USE_DEFAULT_WAIT );
  112.  
  113.       /*
  114.       ** API's to make life a little easier 
  115.       */
  116.  
  117.       virtual BOOL Open( void );
  118.       virtual void Close( void );
  119.       virtual UINT Read( void *buffer, UINT size_of_buffer );
  120.       virtual BOOL Write( void ); // Send whatever is in the output buffer
  121.       virtual BOOL Write( const CString& string_to_write ); // Send the string
  122.       virtual BOOL Write( const CByteArray& data_to_write );
  123.       virtual void Write( const void *buffer, UINT number_of_bytes_to_write );
  124.       virtual DWORD GetErrorCode( void ) const;
  125.  
  126.       /*
  127.       ** Operators
  128.       */
  129.  
  130.       /*
  131.       ** [] when reading comes from the input buffer
  132.       ** [] when writine (putting into array) goes into outputbuffer
  133.       */
  134. };
  135.  
  136. #endif // NAMED_PIPE_CLASS_HEADER
  137.